// 基本思想：将原型链和借用构造函数的技术组合在一块，从而发挥两者之长的一种继承模式。

function Super(name) {
  this.name = name;
  this.colors = ['red', 'green'];
}

Super.prototype.sayName = function() {
  console.log(this.name);
};

function Sub(name, age) {
  Super.call(this, name);
  this.age = age;
}

Sub.prototype = new Super();
// 设置构造器,可通过如下方式创建：new Sub.prototype.constructor('Andy3', 3);
Sub.prototype.constructor = Sub;
Sub.prototype.sayAge = function() {
  console.log(this.age);
};

console.log(Sub.prototype);

var instance1 = new Sub('Andy1', 11);
var instance2 = new Sub('Andy2', 22);
var instance3 = new Sub.prototype.constructor('Andy3', 3);
instance1.colors.push("black");
instance1.sayAge();
instance1.sayName();
console.log(instance1.colors);
instance2.sayAge();
instance2.sayName();
console.log(instance2.colors);
instance3.sayAge();
instance3.sayName();
console.log(instance3.colors);
